import axios from "axios";

const ledgerBaseUrl= 'http://localhost:8082';
const ledgerRequest={
    loadLedgers(ledger,callBack){
        let url = ledgerBaseUrl + "/ledger/list?";
        if(ledger){
            if(ledger.ledgerEncode){
                url += "&ledgerEncode=" + ledger.ledgerEncode;
            }
            if(ledger.ledgerName){
                url += "&ledgerName=" + ledger.ledgerName;
            }
            if(ledger.scmsId){
                url += "&scmsId=" + ledger.scmsId;
            }
            if(ledger.ledgerScms){
                url += "&ledgerScms=" + ledger.ledgerScms;
            }
        }
        axios.get(url)
            .then(res=>{
                callBack(res.data);
            })
    },
    insert(ledger,callBack){
        let url = ledgerBaseUrl + "/ledger/insert";
        axios.post(url,ledger)
            .then(res=>{
                callBack(res.data);
            })
    },
    update(ledger,callBack){
        let url  = ledgerBaseUrl + "/ledger/update";
        axios.put(url,ledger)
            .then(res=>{
                callBack(res.data);
            })
    },
    updateScms(ledger,callBack){
        let url = ledgerBaseUrl + "/ledger/updateScms";
        axios.put(url,ledger)
            .then(res=>{
                callBack(res.data);
            })
    },
    selectById(ledgerId,callBack){
        let url = ledgerBaseUrl + "/ledger/selectById?ledgerId=" + ledgerId;
        axios.get(url)
            .then(res=>{
                callBack(res.data);
            })
    },
    delete(ledgerId,callBack){
        let url = ledgerBaseUrl + "/ledger/delete?ledgerId=" + ledgerId;
        axios.delete(url)
            .then(res=>{
                callBack(res.data);
            })
    }
}

export default ledgerRequest;